﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArraysAndStrings.TwoSum
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[] nums = new int[] { 0,0,3,4};
            foreach (var item in TwoSum(nums, 0))
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }
        public static int[] TwoSum(int[] numbers, int target)
        {
            List<int> list = numbers.ToList();
            int leftIndex = 0;
            int otherValue = 0;
            int[] returnArray = new int[2];
            while (numbers[leftIndex]<= target)
            {
                otherValue = target - numbers[leftIndex];
                if (list.Contains(otherValue))
                {
                    returnArray[0] = leftIndex+1;
                    int index = list.IndexOf(otherValue) + 1;
                    if (index == returnArray[0])
                    {
                        list[leftIndex] = 1001;
                    }
                    returnArray[1] = list.IndexOf(otherValue) + 1;
                    break;
                }
                leftIndex++;
                if (leftIndex>= numbers.Length) break;
            }
            return returnArray;
        }
    }
}
